<?
//require("classCol.php");

session_start();

if(!$_SESSION["tocTab"]){
	
	if ($c=OCILogon($_SESSION["ORCLU"], $_SESSION["OPASS"], $_SESSION["SID"])) {
		
		//query if the user id exist
		//if successed to connect then query the user id
		$user_id 			= $_SESSION["user"];
		$company_sel	= $_SESSION["company"];
		$query  = "select levelmn, ".
		          "       description ".
		          "from userid_dtl ".
		          "where  userid='".$user_id."' ".
		          "       and company='".$company_sel."' ".
		          "       and status=1 ".
		          "order by levelmn asc";
		
		//echo $query ."\n";
		$s = OCIParse($c, $query);
		OCIExecute($s, OCI_DEFAULT);
		$nrows = oci_fetch_all($s, $resultsa);
		
		//print_r($resultsa);
		OCILogoff($c);
		
		//print evertyhing and make em as links
		//due to sysncing then insert 1 data into TOC TAB.
		$tocTab[0][0] = "0";
		$tocTab[0][1] = "MENU";
		$tocTab[0][2] = "tocmenu_0.php";
		if($nrows > 0){
			$y = 1;
			for ($i = 0; $i < $nrows; $i++) {
				$num_filled = 0;
		    foreach ($resultsa as $dataa) {
		    	//check if the prev number already inserted
		    	if($num_filled != 1){
		    		$prev_num = $dataa[$i];
		    		
		    		//echo $prev_num ." prev num\n";
		    		$num_filled = 1;
		    	}
		    	
		    	//num_filled alread inserted then continue with the array fecthing
		    	if($num_filled == 1){
		    		//$url_str = "tocmenu_1.htm" ;
		    		//print_r($prevnum);
		    		//echo  "Seharusnya ada string";
		    		/*
		    		switch((string)$prev_num[0]){
							case "J" :
								$prev_num[0] = "1";
								break;
							case "K" :
								$prev_num[0] = "2";
								break;
							case "L" :
								$prev_num[0] = "3";
								break;
							case "M" :
								$prev_num[0] = "4";
								break;
							case "N" :
								$prev_num[0] = "5";
								break;
							case "O" :
								$prev_num[0] = "6";
								break;
							case "P" :
								$prev_num[0] = "7";
								break;
							case "Q" :
								$prev_num[0] = "8";
								break;
							case "R" :
								$prev_num[0] = "9";
								break;
							default:
								break;
						}*/
		    		$url_str ="tocmenu_" .$prev_num .".php";
		    		//echo $url_str . "url str \n";
		    		//$tocTab  = array(array($prev_num,$data[$i],$url_str));
		    		
		    		$tocTab[$y][0]  = $prev_num;
		    		$tocTab[$y][1]  = $dataa[$i];
		    		$tocTab[$y][2]  = $url_str;
		    		
		    		//print_r($tocTab);
		    	}	
		    }
		    $y++;
		  }
		  $_SESSION["tocTab"] = $tocTab;
		}
	}
	$nCols = 4; 
}else{
	//echo "tocTab filled.\n";
	//print_r($tocTab);
	$tocTab = $_SESSION["tocTab"];
	$nCols = 4; 
}
	
session_write_close();
?>